﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace GDI_应用案例.Pages.Controls._3D
{
    [StructLayout(LayoutKind.Explicit)]
    public unsafe struct RectangleF3D
    {
        public static RectangleF3D Empty;
        [FieldOffset(0)]
        public float X;
        [FieldOffset(4)]
        public float Y;
        [FieldOffset(8)]
        public float Z;
        [FieldOffset(12)]
        public float Width;
        [FieldOffset(16)]
        public float Height;
        [FieldOffset(20)]
        public float Depth;
        public RectangleF3D(float x, float y, float z, float width, float height, float depth)
        {
            X = x;
            Y = y;
            Z = z;
            Width = width;
            Height = height;
            Depth = depth;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void ToPoint3D(Point3D* pf) => CreateCuboid(X, Y, Z, Width, Height, Depth, pf);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public Point3D[] ToPoint3D()
        {
            Point3D[] point3Ds = new Point3D[8];
            fixed (Point3D* pf = point3Ds)
                ToPoint3D(pf);
            return point3Ds;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void CreateCuboid(float x, float y, float z, float width, float height, float depth, Point3D* pf)
        {
            Point3D* p = pf;
            p->X = x; p->Y = y; p->Z = z;
            p += 1;
            p->X = x + width; p->Y = y; p->Z = z;
            p += 1;
            p->X = x + width; p->Y = y + height; p->Z = z;
            p += 1;
            p->X = x; p->Y = y + height; p->Z = z;

            p += 1;
            p->X = x; p->Y = y; p->Z = z + depth;
            p += 1;
            p->X = x + width; p->Y = y; p->Z = z + depth;
            p += 1;
            p->X = x + width; p->Y = y + height; p->Z = z + depth;
            p += 1;
            p->X = x; p->Y = y + height; p->Z = z + depth;
        }
    }
}
